<template>
<div class="app">
  <transition>
    <router-view></router-view>
  </transition>
</div>
</template>

<script>
import 'weui'
// import {sessionStorage} from 'config/utils'
import { mapState, mapActions, mapMutations } from 'vuex'  // mapActions
import {cookie, removeCookie} from 'config/utils'
import {getI9RIA} from 'service/getData'
export default {
  name: 'app',
  data () {
    return {
      memberInfo: {}
    }
  },
  components: {
  },
  computed: {
    ...mapState([
      'I9RIA', // 获取基本信息
      'wxJsApiConf'
    ])
  },
  created () {
    // this.$router.push(window.location.hash.replace('#', ''))
    if (!cookie('unionid')) {
      removeCookie('unionid')
      cookie('unionid', window.I9RIA.unionid) // 避免清除缓存后cookie中没有unionid
      this.initData()
    } else {
      this.getI9RIA() // 获取用户配置信息
    }
  },
  methods: {
    ...mapActions([
      'getI9RIA'
    ]),
    ...mapMutations([
      'RECORD_I9RIA' // 登陆成功后保存用户信息
    ]),
    async initData () {
      let tmpData = await getI9RIA()
      if (tmpData.code === 9999) {
        this.$router.push('/nofound')
      } else {
        this.RECORD_I9RIA(tmpData)
        this.$router.push(window.location.hash.replace('#', ''))
      }
    }
  }
}
</script>
<style>
@import './assets/css/base.css';
@import './assets/css/common.css';
</style>
